/*
 * WtDocument.cs - Wordtrainer
 * 
 * Copyright (C) 1998-2008 Markus Kilås
 *               
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 * 
 * Authors:
 *   Markus Kilås <markus@markuspage.com>
 *
 */

using System;
using System.Collections;

namespace WtSharp
{
	
	
	public class WtDocument
	{
		private IDictionary m_info;
		private ArrayList m_words;
		private string m_titleForeign;
		private string m_titleTranslation;
		private string m_fileName;
		private string m_fileTitle;
		private bool m_bChanged;
		private bool m_bNew;
		
		public WtDocument()
		{
			initialize();
		}
		
		public WtDocument(string fileName)
		{
			initialize();
			m_fileName = fileName;
			m_fileTitle = GetFileTitle(fileName);
		}
		
		private void initialize()
		{
			m_info = new Hashtable();
			m_words = new ArrayList();
			m_titleForeign = "Forign word:";
			m_titleTranslation = "Translation:";
			m_fileTitle = m_fileName = "Untitled.wt2";
			m_bChanged = false;
			m_bNew = true;
			Info["OWNER"] = "";
			Info["DESCRIPTION"] = "";
			Info["TITLE"] = "";
		}
		
		public IDictionary Info
		{
			get
			{
				return m_info;
			}
			set
			{
				m_info = value;
			}
		}
		
		public ArrayList Words
		{
			get
			{
				return m_words;
			}
			set
			{
				m_words = value;
			}
		}
		
		public bool Changed
		{
			get
			{
				return m_bChanged;
			}
			set
			{
				m_bChanged = value;
			}
		}
		
		public void Close()
		{
			initialize();
		}
		
		public bool New
		{
			get 
			{
				return m_bNew;
			}
			set
			{
				m_bNew = value;
			}
		}
		
		public string FileName
		{
			get
			{
				return m_fileName;
			}
			set
			{
				m_fileName = value;
			}
		}
		
		public string FileTitle
		{
			get
			{
				return m_fileTitle;
			}
			set
			{
				m_fileTitle = value;
			}
		}
		
		public static string GetFileTitle(string filePath)
		{
			int lastSeparator = filePath.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
			if(lastSeparator != -1)
			{
				return filePath.Substring(lastSeparator+1, filePath.Length-(lastSeparator+1));
			}
			else
				return filePath; 
		}
		
		public string TitleForeign
		{
			get
			{
				return m_titleForeign;
			}
			set
			{
				m_titleForeign = value;
			}
		}
		
		public string TitleTranslation
		{
			get
			{
				return m_titleTranslation;
			}
			set
			{
				m_titleTranslation = value;
			}
		}
	}
}
